package com.foreknow.elm.controller;


import com.foreknow.elm.po.Cart;
import com.foreknow.elm.po.OrderDetailet;
import com.foreknow.elm.po.Orders;
import com.foreknow.elm.service.CardService;
import com.foreknow.elm.service.OrderDetailetService;
import com.foreknow.elm.service.OrdersService;
import com.foreknow.elm.service.impl.CardServiceImpl;
import com.foreknow.elm.service.impl.OrderDetailetServiceImpl;
import com.foreknow.elm.service.impl.OrdersServiceImpl;
import com.foreknow.elm.util.DBUtil;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.foreknow.elm.po.Orders;
import com.foreknow.elm.service.OrdersService;
import com.foreknow.elm.service.impl.OrdersServiceImpl;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;


public class OrdersController {
    OrdersService ordersService = new OrdersServiceImpl();
    public int createOrders(HttpServletRequest request){
        String uid = request.getParameter("userId");
        Integer bid = Integer.parseInt(request.getParameter("businessId"));
        Integer daid = Integer.parseInt(request.getParameter("daId"));
        double total = Double.parseDouble(request.getParameter("orderTotal"));
        Orders orders = new Orders();
        orders.setUserId(uid);
        orders.setBusinessId(bid);
        orders.setDaId(daid);
        orders.setOrderTotal(total);
        int a = ordersService.sinsert(orders);
        return a;
    }

    public Orders getOrdersById(HttpServletRequest request){
        Integer oid = Integer.parseInt(request.getParameter("orderId"));
        Orders orders = ordersService.squeryobo(oid);
        return orders;
    }

    public List<Orders> listOrdersByUserId(HttpServletRequest request){
        String uid = request.getParameter("userId");
        List<Orders> list = new ArrayList<>();
        list = ordersService.squeryall(uid);
        return list;
    }

}


